<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:cote="http://java.sun.com/jsf/composite/componentes">

    <ui:composition template="/plantillas/plantillaPrincipal.xhtml">
        <ui:define name="contenido">
            <f:view>
                <h:form>
                    <h:panelGrid columns="1" style="width: 650px;margin: 0px auto;">
                        <cote:componenteFindCliente id="findCliente" 
                                                    lblbtnfind="ASIGNAR LINEA CREDITO A CLIENTE"                                                                                                      
                                                    update=":formLineaCredito:dataTablaClientesCreditos"/>
                    </h:panelGrid> 
                </h:form>
                <h:form id="formLineaCredito">
                    <p:messages id="messages" />
                    <p:panel id="pnlLineaCredito" widgetVar="buscar" toggleable="true"
                             header="Linea de Credito de Clientes" collapsed="#{BKVentaLineaCredito.listaVentaLineaCredito ne null}"
                             style="width:650px;margin: 0px auto">


                        <br/>

                        <table border="0" cellspacing="3" cellpadding="3">                                               
                            <tbody>
                                <tr>

                                    <td>
                            <h:outputLabel id="lblRazon" value="CLIENTE: " />
                            </td>
                            <td>
                            <p:inputText onkeyup="cambiarMayuscula(this)" id="txtRazon"  value="#{BKVentaLineaCredito.razon}" />
                            </td>
                            <td>
                            <p:commandButton id="btnBuscar" value="BUSCAR"                                                          
                                             action="#{MBVentaLineaCredito.buscar()}"
                                             update="pnlLineaCredito,dataTablaClientesCreditos,messages"
                                             oncomplete="listaLineaCredito.show();buscar.toggle()" style="font-size: 12px" />

                            </td>


                            </tr>


                            </tbody>
                        </table>




                    </p:panel>

                    <p:panel id="pnlListarLineaCredito"
                             header="Lista Lineas de Credito" closable="true"
                             style="width: 100%;margin: 10px auto" widgetVar="listaLineaCredito"
                             visible="#{(BKVentaLineaCredito.listaVentaLineaCredito eq null)?false:true}">

                        <p:dataTable id="dataTablaClientesCreditos" var="credito"
                                     value="#{BKVentaLineaCredito.listaVentaLineaCredito}" widgetVar="lista"
                                     emptyMessage="No se encontraron Facturas"
                                     filteredValue="" rowIndexVar="rowIndex" paginator="true" rows="20"
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} 
                                     {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                     rowsPerPageTemplate="20,40,60" paginatorPosition="bottom" styleClass="datable-busqueda">

                            <f:facet name="header">                                                                                                                                           
                            </f:facet>

                            <p:column id="idColumnaNum" style="width: 5%" >
                                <f:facet name="header">  
                                    <h:outputText value="Num." />  
                                </f:facet>
                                <h:outputText value="#{rowIndex+1}" />
                            </p:column>

                            <p:column id="idColumnaRUC" style="width: 10%" sortBy="#{credito.ruc}" >
                                <f:facet name="header">  
                                    <h:outputText value="RUC" />  
                                </f:facet>
                                <h:outputText value="#{credito.ruc}" />
                            </p:column>

                            <p:column id="idColumnaRazonSocial" style="width: 45%" sortBy="#{credito.rasonSocial}" >
                                <f:facet name="header">  
                                    <h:outputText value="Razon Social" />  
                                </f:facet>
                                <h:outputText value="#{credito.rasonSocial}" />
                            </p:column>

                            <p:column id="idColumnaCredito" style="text-align: right;width: 10%" sortBy="#{credito.lineaCredito}">
                                <f:facet name="header">  
                                    <h:outputText value="Linea Crédito" />  
                                </f:facet>
                                <h:outputText value="#{credito.lineaCredito}" >
                                    <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
                                </h:outputText>
                            </p:column>

                            <p:column id="idColumnaUsado" style="text-align: right;width: 10%" sortBy="#{credito.lineaUsada}" >
                                <f:facet name="header">  
                                    <h:outputText value="Linea Usada" />  
                                </f:facet>
                                <h:outputText value="#{credito.lineaUsada}" >
                                    <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
                                </h:outputText>
                            </p:column>

                            <p:column id="idColumnaDisponible" style="text-align: right;width: 10%" sortBy="#{credito.lineaSaldo}" >
                                <f:facet name="header">  
                                    <h:outputText value="Linea Disponible" />  
                                </f:facet>
                                <h:outputText value="#{credito.lineaSaldo}" >
                                    <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
                                </h:outputText>
                            </p:column>


                            <p:column id="idColumnaAcciones" style="width: 10%"  headerText="#{message['general.label.tipoAcesso']}" exportable="false">

                                <p:commandButton icon="ui-icon-pencil" title="#{message['general.button.editar']}" actionListener="#{MBVentaLineaCredito.seleccionar()}" oncomplete="actualizarMonto.show()" ajax="true" update=":formLineaCredito:dlgCredito" >
                                    <f:setPropertyActionListener value="#{credito}" target="#{BKVentaLineaCredito.ventaLineaCreditoSeleccionado}" />  
                                </p:commandButton>                                                  
                                <p:commandButton icon="ui-icon-bookmark" title="#{message['general.button.ver']}" action="#{MBVentaLineaCredito.ver()}" immediate="true" ajax="false">
                                    <f:setPropertyActionListener value="#{credito}" target="#{BKVentaLineaCredito.ventaLineaCreditoSeleccionado}" />  
                                </p:commandButton>
                            </p:column>


                        </p:dataTable>
                    </p:panel>

                    <p:dialog id="dlgCredito"  header="Linea de Credito" widgetVar="actualizarMonto" modal="true"  height="120" >  
                        <h:panelGrid style="width: auto;margin:0px auto;border:0px;padding: 0 5px" columns="2">

                            <h:outputLabel id="lblCreditoBase" value="Credito Base " />
                            <p:inputText id="txtCreditoBase" value="#{BKVentaLineaCredito.credito}" disabled="#{BKVentaLineaCredito.ventaLineaCreditoSeleccionado.creditoBase}"/>

                            <h:outputLabel id="lblCreditoVariable" value="Variación " />
                            <p:inputText id="txtCreditoVariable"   value="#{BKVentaLineaCredito.monto}" disabled="#{BKVentaLineaCredito.estado}"/>

                            <p:commandButton id="btnAceptar" value="Guardar"  oncomplete="actualizarMonto.hide()"  
                                             actionListener="#{MBVentaLineaCredito.actualizar()}" process="@this,txtCreditoBase,txtCreditoVariable,messages" ajax="true" update="dataTablaClientesCreditos"/>  
                            <p:commandButton id="btnCancelar" value="Cancelar" onclick="actualizarMonto.hide()" type="button" />
                        </h:panelGrid>
                    </p:dialog>


                </h:form>
            </f:view>
        </ui:define>
    </ui:composition>

</html>